package com.pipi.fanglan.dao;

import com.pipi.fanglan.model.WorkOrder;
import com.pipi.fanglan.model.form.ConfirmOrderForm;
import org.apache.http.message.BasicNameValuePair;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by pipi on 2017/7/16.
 */
@Component
public class OrderDao {

    public List<WorkOrder> orderList(String html){
        Document doc = Jsoup.parse(html);
        Element table = doc.getElementById("taskList");
        if(table == null){
            return null;
        }
        Elements trs = table.getElementsByTag("tr");
        List<WorkOrder> orderList = new ArrayList<WorkOrder>();

        Iterator<Element> iterators = trs.iterator();
        while (iterators.hasNext()){
            Element tr = iterators.next();
            Elements tds = tr.getElementsByTag("td");
            if(tds.size()>0){
                WorkOrder order = new WorkOrder();
                order.setWornStatus(tds.get(0).html());
                order.setOrderNum(tds.get(2).getElementsByTag("a").first().html());
                order.setDetailUrl(tds.get(2).getElementsByTag("a").attr("href"));
                order.setOrderTheme(tds.get(3).html());
                order.setDispatchTime(tds.get(4).html());
                order.setHandlerLimitTime(tds.get(5).html());
                order.setHandleLink(tds.get(6).html());
                order.setOrderStatus(tds.get(7).html());
                order.setOrderOwner(tds.get(8).html());
                orderList.add(order);
            }

        }
        return orderList;
    }


}
